package com.xca.znb.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class ProcurementDBHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "procurement.db";
    private static final int DATABASE_VERSION = 1;

    public static final String TABLE_PROCUREMENT = "procurement";
    public static final String PROCUREMENT_ID = "id";
    // Assuming 'type' is a text field, but if it's an enum or identifier, consider using INTEGER
    public static final String PROCUREMENT_TYPE = "type";
    public static final String PROCUREMENT_VARIETY = "variety"; // 品种
    // If 'need' represents a quantity, consider using INTEGER or REAL
    public static final String PROCUREMENT_NEED = "need";
    public static final String PROCUREMENT_UNIT = "unit";
    public static final String PROCUREMENT_ORIGIN = "origin"; // 期望货源地
    public static final String PROCUREMENT_CYCLE = "cycle"; // 采购周期
    public static final String PROCUREMENT_DELIVERY = "delivery"; // 收货地址
    public static final String PROCUREMENT_TEXT = "text";
    // If 'phone' is a number, consider using INTEGER. If it's a string, TEXT is fine.
    public static final String PROCUREMENT_PHONE = "phone";

    private static final String CREATE_TABLE_PROCUREMENT = "CREATE TABLE " + TABLE_PROCUREMENT + "("
            + PROCUREMENT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," // Added space before INTEGER
            + PROCUREMENT_TYPE + " TEXT," // Assuming type is text
            + PROCUREMENT_VARIETY + " TEXT,"
            + PROCUREMENT_NEED + " TEXT," // Changed from TEXT to potentially INTEGER or REAL if needed
            + PROCUREMENT_UNIT + " TEXT,"
            + PROCUREMENT_ORIGIN + " TEXT,"
            + PROCUREMENT_CYCLE + " TEXT,"
            + PROCUREMENT_DELIVERY + " TEXT,"
            + PROCUREMENT_TEXT + " TEXT,"
            + PROCUREMENT_PHONE + " TEXT" // Changed from TEXT to potentially INTEGER if needed
            + ")";

    public ProcurementDBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_PROCUREMENT);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_PROCUREMENT);
        onCreate(db);
    }
}